import BaseUtil from '@/BaseUtil';
import MathUtil from '@/MathUtil';
import SelectUtil from '@/SelectUtil';
import UnitCommon from 'code/Core/Common/UnitCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 旋风斧
 **/
export default class BossSpell_XuanFengAxe extends AbilityBase {
    static instance: BossSpell_XuanFengAxe;
    constructor(id: string = 'Asm2') {
        super(id);
        BossSpell_XuanFengAxe.instance = this;
        this.init();
        se.onUnitSpellEffect(this.onSpellEffect.bind(this), this.id);
    }
    init() {}
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        BossAbilityManagerInstance.text('旋风飞牮', source);
        BaseUtil.runLater(1, () => {
            this.effect.call(this, source);
            source = null;
        });
    }
    effect(source: unit) {
        let x = GetUnitX(source);
        let y = GetUnitY(source);
        let f = GetUnitFacing(source);
        let f1 = f + 90;
        let f2 = f - 90;
        let { x: x1, y: y1 } = MathUtil.polarProjection(x, y, 50, f1);
        let { x: x2, y: y2 } = MathUtil.polarProjection(x, y, 50, f2);
        let dis = 0;
        let u1 = CreateUnit(GetOwningPlayer(source), FourCC('vff1'), x1, y1, f1);
        let u3 = CreateUnit(GetOwningPlayer(source), FourCC('vff0'), x1, y1, f1);
        let u2 = CreateUnit(GetOwningPlayer(source), FourCC('vff1'), x2, y2, f2);
        let u4 = CreateUnit(GetOwningPlayer(source), FourCC('vff0'), x2, y2, f2);
        BaseUtil.onTimer(0.05, (c) => {
            let p = Sin((c / 40) * Math.PI);
            dis = 50 + p * 200;
            x = GetUnitX(source);
            y = GetUnitY(source);
            f1 += 24;
            f2 += 24;
            f1 %= 360;
            f2 %= 360;
            x1 = x + CosBJ(f1) * dis;
            y1 = y + SinBJ(f1) * dis;
            x2 = x + CosBJ(f2) * dis;
            y2 = y + SinBJ(f2) * dis;
            SetUnitX(u1, x1);
            SetUnitY(u1, y1);
            SetUnitX(u3, x1);
            SetUnitY(u3, y1);
            SetUnitX(u2, x2);
            SetUnitY(u2, y2);
            SetUnitX(u4, x2);
            SetUnitY(u4, y2);
            if (c % 2 == 0) {
                let dmg = UnitCommon.取攻击(source) / 5;
                let es = [].concat(SelectUtil.getEnemyUnitsInRange(u1, 75), SelectUtil.getEnemyUnitsInRange(u2, 75));
                for (let e of es) {
                    DamageSystemInstance.applyAttackDamage(e, source, dmg);
                    DestroyEffect(AddSpecialEffectTarget('Objects\\Spawnmodels\\Other\\BeastmasterBlood\\BeastmasterBlood.mdl', e, 'origin'));
                }
            }
            if (c >= 40) {
                KillUnit(u1);
                KillUnit(u2);
                KillUnit(u3);
                KillUnit(u4);
            }
            return c < 40;
        });
    }
    onSpellEffect() {
        this.cast(GetSpellTargetX(), GetSpellTargetY(), GetTriggerUnit(), GetSpellTargetUnit());
    }
}
